<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    <h1>hello world</h1>
    <h1>hello world</h1>
    <h1>hello world</h1>
    <h1>hello world</h1>
    <h1>hello world</h1>
    <script>
        let h1List = document.querySelectorAll("h1");
        for(let i in h1List){
            h1List[i].onclick = function(){
                // this.className = "active";
                if(this.className === "active"){
                    this.className = ""
                }else{
                    this.className = "active"
                }
            }
        }
    </script>
</body>
</html>